package net.molchat.web;


import javax.servlet.http.HttpServletRequest;


/**
 * Some Url utilites for web development.
 * 
 * @author Valentyn Markovich
 * 
 */
public abstract class UrlUtil {


/**
 * @param request
 * @return Full reconstructed request URL
 */
public static StringBuffer ReconstructFullUrl(HttpServletRequest request) {


	StringBuffer url = request.getRequestURL();
	addPathAndQuery(url, request);
	return url;
}


private static StringBuffer addPathAndQuery(StringBuffer url, HttpServletRequest request) {

	if (request.getPathInfo() != null) {
		url.append(request.getPathInfo());
	}
	if (request.getQueryString() != null) {
		url.append('?').append(request.getQueryString());
	}
	return url;
}


/**
 * @param request
 * @return Full reconstructed request URI
 */
public static StringBuffer ReconstructFullUri(HttpServletRequest request) {


	StringBuffer url = new StringBuffer(request.getRequestURI());
	addPathAndQuery(url, request);
	return url;
}


}
